<?php
session_start();
header("Content-type:text/html;charset=utf-8");
require('config.inc.php');
//分页
$pagesize = 2;
if(isset($_GET['page']) && $_GET['page'] != ''){
	$page = $_GET['page'];
}else{
	$page = 1;
}

if(isset($_GET['out'])){
	unset($_SESSION['login']);
	echo "<script>location.href='index.php';alert(删除成功);</script>";
}

//连表组合查询语句
$sql = "SELECT c1 . * , c2.reply_time, c2.reply FROM info c1 LEFT JOIN reply c2 ON (c1.id = c2.info_id) ORDER BY c1.id DESC";
mysql_query("set names utf8");

//获得结果集中的记录数
$numRecord = mysql_num_rows(mysql_query($sql));
$totalpage = ceil($numRecord / $pagesize);
$recordSql = $sql." LIMIT ".$page*$pagesize.",".$pagesize;
$result = mysql_query($recordSql);

//回复
if($_SESSION['login'] != 'admin'){
	echo "<script>alert('管理员没登录，请重新登录');location.href='login.php';</script>";
}else{
	if(isset($_GET['reply']) && $_SESSION['login'] == 'admin'){
		$reply = $_GET['reply'];
	}
}


?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言预览页面</title>
</head>
<body>
	<h1>留言板</h1>
	<div style="display:none;" id="replay_content">回复内容</div>
	<div>管理员：<span><?php  if($_SESSION['login'] == 'admin' && isset($_SESSION['login'])){echo $_SESSION['login']."&nbsp;&nbsp;<a href='index.php?out=out'>退出</a>";}else{ echo "<a href='login.php'>请登录</a>";} ?></span>
	</div>
	<hr />
	<?php
		//循环遍历结果集中的留言信息
		while($rs = mysql_fetch_object($result)){
			//echo nl2br(htmlspecialchars($rs->content));
			//echo $rs->content."<br />";
			//该部分输出留言相关的信息

		//释放MYSQL数据库query返回所占用的内存
		//mysql_free_result($result);
?>
	<div>
		<span>第<?php echo nl2br(htmlspecialchars($rs->id))?>条：<a href="index.php?reply=<?php echo $rs->id ?>" id="replay">回复</a></span> |
		<span><a href="del.php?id=<?php echo $rs->id ?>">删除</a></span> | <span><a href="edit.php?id=<?php echo $rs->id ?>">编辑</a></span> |
		<span><a href="post.html">我要留言</a></span>
	</div>
	<script>
		function $(id){
			return document.getElementById(id);
		}
		$("replay").onclick = function(){
			$("replay_content").style.display = 'block';
			return false;
		};
	</script>
	<div>
		<span><?php echo $rs->name;?></span>
		<span><?php echo $rs->content_time;?></span>
	</div>
	<div>
		<h3>[留言内容]:</h3>
		<div><?php echo nl2br(htmlspecialchars($rs->content))?></div><br />
		回复标题：你好  回复人：管理员  回复时间：[2012-02-21]<br /><br /><br />
		[管理员回复留言区]
	</div>
	<hr />
	
	<?php
		}
	?>
	<div style="margin-top:20px;">
		<span><a href='index.php?page=<?php if ($page<$totalpage-1) echo $page+1;?>'>下一页</a></span>
		<?php
			echo "<span>";
			for($i=1;$i<=$totalpage;$i++){
				echo "<a href='index.php?page=".($i)."'>".($i)."</a>&nbsp;&nbsp;";
			}			
			echo "</span>";
		?>
		<span><a href="index.php?page=<?php if($page>0) echo $page; ?>">上一页</a></span>
		<span>总共：<?php echo $numRecord; ?>个</span><span>&nbsp;&nbsp;<?php echo $page."/".$totalpage; ?></span>
	</div>
	<br /><br /><br /><br />
<style>
.current{color:green;}
</style>
</body>
</html>
